home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / www / amitrix / httx17.lha / HTTX / HTTXPlugin.awebrx < prev    next >
Text File  |  1998-03-07  |  6KB  |  327 lines

  1. /*
  2.     Convert current document to TEXT using HTTX
  3.     $VER: HTTXPlugin 2.1 (23.1.98) by Gabriele Favrin (favrin@tin.it)
  4. */
  5.  
  6. options results
  7. options failat 999
  8.  
  9. parse ARG mode mode_data .
  10. parse SOURCE . . . resolved .
  11.  
  12. plugin_path = FindPath(resolved)
  13.  
  14. 'GetCFG TEMPPATH VAR' prefs_temppath
  15. If Right(prefs_temppath, 1) ~= "/" & Right(prefs_temppath, 1) ~= ":" then do
  16.     prefs_temppath=prefs_temppath"/"
  17. End
  18.  
  19. req_title = '"Save as text"'
  20. temp_out     = prefs_temppath"temp_HTTXP_Output.txt"
  21. temp_name = prefs_temppath"temp_HTTXP_file"
  22. temp_inc  = prefs_temppath"temp_HTTXP_header"
  23. del_list     = prefs_temppath"temp_HTTXP_#?"
  24. eol         = '0A'x
  25. trg         = ""
  26. force         = ""
  27. append     = ""
  28. string     = ""
  29. option     = ""
  30. converted = 0
  31.  
  32. prefs_info     = 0
  33. prefs_preview= 0
  34. prefs_report = 1
  35. prefs_savedir= "ram:"
  36. prefs_save_noheader=0
  37. prefs_print_noheader=0
  38.  
  39. Call ReadCfg()
  40.  
  41. If (mode == "TARGET") then do
  42.     trg="TARGET" mode_data
  43. End
  44.  
  45. 'Get URL VAR' doc_url trg
  46. 'Get TITLE VAR' doc_title trg
  47.  
  48. 'GetCFG FRAMES'
  49. If result == 0 then do
  50.     frms.0=0
  51. End
  52. else do
  53.     'Get FRAMES ALL' trg 'STEM' frms
  54. End
  55.  
  56. If (frms.0 = 0) then do
  57.     If getName() == 1 then do
  58.         Call SaveHTML()
  59.         Call Convert()
  60.         Call CleanUp(1)
  61.     End
  62. End
  63. else do
  64.     prefs_report=0
  65.  
  66.     'Request 'req_title' "Selected document contains frames." "Convert _All|_Select frame(s)|_Cancel"'
  67.     If rc == 5 then exit 0
  68.     option=result
  69.  
  70.     If option == 1 then do
  71.         If ~getName() then do
  72.             exit 0
  73.         End
  74.     End
  75.  
  76.     do ct=0 for (frms.0)+1
  77.         If ct > 0 then do
  78.             doc_url=frms.ct.url
  79.             doc_title=frms.ct.name
  80.             trg="TARGET" frms.ct.id
  81.         End
  82.  
  83.         If option == 1 then do
  84.             'Get FRAMESET' trg
  85.             If (result == 0) then do
  86.                 If converted then do
  87.                     drop append
  88.                     string=eol||"----"||eol
  89.                 End
  90.  
  91.                 Call SaveHTML()
  92.                 Call Convert()
  93.                 Call CleanUp(0)
  94.             End
  95.         End
  96.         else do
  97.             'Open "'doc_url'"'
  98.             'Wait "'doc_url'"'
  99.  
  100.             'Get FRAMESET'
  101.             If (result == 0) then do
  102.                 'Request 'req_title' "Convert this document?" "_Yes|_No|_Cancel"'
  103.                 If (rc == 5) then do
  104.                     Call CleanUp(1)
  105.                     If (ct > 0) then do
  106.                         'GO' ct 'BACK'
  107.                     End
  108.                     exit 0
  109.                 End
  110.  
  111.                 If result == 1 then do
  112.                     trg=""
  113.                     string=""
  114.                     If getName() == 1 then do
  115.                         Call SaveHTML()
  116.                         Call Convert()
  117.                         Call CleanUp(0)
  118.                     End
  119.                 End
  120.             End
  121.         End
  122.     End
  123.  
  124.     If option == 1 then do
  125.         If (prefs_preview == 1) then do
  126.             If (Preview() == 1) then do
  127.                 Call DisplayOutput()
  128.             End
  129.         End
  130.         else do
  131.             Call DisplayOutput()
  132.         End
  133.         Call CleanUp(1)
  134.     End
  135.     else do
  136.         If (option == 2) & (ct > 0) then do
  137.             'GO' ct-1 'BACK'
  138.         End
  139.         Call CleanUp(1)
  140.     End
  141. End
  142.  
  143. exit 0
  144.  
  145.  
  146. CleanUp:
  147.     parse ARG mode_all
  148.  
  149.     address command 'C:Delete >NIL: QUIET' del_list
  150.  
  151.     If mode_all == 1 then do
  152.         local_savedir=FindPath(save_file)
  153.  
  154.         If prefs_savedir ~= local_savedir then do
  155.             prefs_savedir=local_savedir
  156.             address command 'SetEnv HTTXPlugin.savedir "'prefs_savedir'"'
  157.         End
  158.     End
  159.     return
  160.  
  161.  
  162. SaveHTML:
  163.     'SaveAs "'temp_name'" NOICON' trg
  164.     If (rc ~= 0) then do
  165.         'Request 'req_title' "Error while saving HTML on temporary path*N *N'prefs_temppath'" "_Ok" NOWAIT'
  166.         exit 0
  167.     End
  168.     return
  169.  
  170.  
  171. GetName:
  172.     html_name=Translate(doc_url,,'`~"=#?/:;\*%()[]<>'||"'")
  173.     html_name=Word(html_name, Words(html_name))
  174.  
  175.     'RequestFile 'req_title' FILE="'prefs_savedir||html_name'.txt" SAVEMODE'
  176.     If (rc == 5) then return 0
  177.     save_file=result
  178.  
  179.     If (Right(save_file, 1) == ":") | (Right(save_file, 1) == "/") then
  180.         save_file=save_file||html_name'.txt'
  181.  
  182.     html_name=prefs_temppath||html_name
  183.     return 1
  184.  
  185.  
  186. Convert:
  187.     'Get MIME VAR' mtype trg
  188.     If (Upper(mtype) == "TEXT/HTML") then do
  189.         drop force
  190.     End
  191.     else do
  192.         force=""
  193.     End
  194.  
  195.     Call PrepareFile()
  196.  
  197.     res=httx()
  198.     If (res == 212) then do
  199.         'Request 'req_title' "File is not HTML! Save anyway?" "_Save|_Cancel"'
  200.  
  201.         If (rc ~= 5) then do
  202.             address command 'C:Copy "'temp_name'" "'save_file'"'
  203.             prefs_report=0
  204.             res=0
  205.             Call DisplayOutput()
  206.         End
  207.     End
  208.     else do
  209.         If option ~= 1 then do
  210.             If (res ~= 0) then do
  211.                 del_list=del_list '"'save_file'"'
  212.                 If option ~= 2 then do
  213.                     Call DisplayOutput()
  214.                 End
  215.             End
  216.             else do
  217.                 If prefs_preview == 1 then do
  218.                     If Preview() == 1 then do
  219.                         If option ~= 2 then do
  220.                             Call DisplayOutput()
  221.                         End
  222.                     End
  223.                 End
  224.                 else do
  225.                     If option ~= 2 then do
  226.                         Call DisplayOutput()
  227.                     End
  228.                 End
  229.             End
  230.         End
  231.     End
  232.     converted=1
  233.     return
  234.  
  235.  
  236. httx:
  237.     address command '"'plugin_path'HTTX" >"'temp_out'" "'temp_name'" "'save_file'" INCLUDE="'temp_inc'" NOHEADER' force append
  238.     return rc
  239.  
  240.  
  241. DisplayOutput:
  242.     If (prefs_report == 1) then do
  243.         'Open "file:///'temp_out'" RELOAD'
  244.         'Wait "file:///'temp_out'"'
  245.     End
  246.     else do
  247.         If (res == 0) then do
  248.             'Request 'req_title' "File saved as*N'save_file'" "_Ok" NOWAIT'
  249.         End
  250.         else do
  251.             'Request 'req_title' "Error 'rc'" "_Ok" NOWAIT'
  252.         End
  253.     End
  254.     return
  255.  
  256.  
  257. Preview:
  258.     'Get SCREEN VAR' prefs_screen
  259.     address command 'SYS:Utilities/Multiview 'save_file' pubscreen='prefs_screen
  260.     drop result
  261.  
  262.     'Request 'req_title' "File converted." "_Ok|_Delete"'
  263.  
  264.     If (result ~= 1) then do
  265.         del_list=del_list '"'save_file'"'
  266.     End
  267.     return result
  268.  
  269.  
  270. PrepareFile:
  271.     If Open(fp, temp_inc, 'W') then do
  272.         If (prefs_save_noheader == 0) then do
  273.             If (prefs_info == 1) then do
  274.                 'Get INFO STEM' infos trg
  275.                 If (infos.0 > 0) then do
  276.                     string=string||eol||"Header:"||eol
  277.  
  278.                     do ctx=1 for infos.0
  279.                         If (infos.ctx.type ~= "CACHE") then do
  280.                             string=string||infos.ctx.value||eol
  281.                             If infos.ctx.type == "LINK" then string=string||eol||infos.ctx.url
  282.                         End
  283.                     End
  284.                 End
  285.             End
  286.  
  287.             string=string||eol||'URL  : 'doc_url||eol'Title: 'doc_title
  288.         End
  289.  
  290.         WriteCH(fp, string)
  291.         Call Close(fp)
  292.     End
  293.     return
  294.  
  295.  
  296. ReadCfg:
  297.     If Open(rcfg_fp, 'ENV:HTTXPlugin.config', 'R') then do
  298.         cfg=ReadLN(rcfg_fp)
  299.  
  300.         If Left(cfg, 6) == "prefs_" then do
  301.             interpret translate(strip(cfg), ';',' ')
  302.             prefs_savedir=Translate(prefs_savedir, ' ', ';')
  303.         End
  304.  
  305.         Call Close(rcfg_fp)
  306.     End
  307.  
  308.     If Open(rcfg_fp, 'ENV:HTTXPlugin.savedir', 'R') then do
  309.         prefs_savedir2=ReadLN(rcfg_fp)
  310.         If prefs_savedir2 ~= "" then prefs_savedir=prefs_savedir2
  311.         Call Close(rcfg_fp)
  312.     End
  313.     return
  314.  
  315.  
  316. FindPath:
  317.     procedure
  318.  
  319.     parse ARG pathf
  320.     dir_pos=Max(lastpos('/', pathf), lastpos(':', pathf))
  321.     If dir_pos > 0    then do
  322.         return(left(pathf,dir_pos))
  323.     End
  324.     else do
  325.         return('')
  326.     End
  327.